package com.kede.api.stand.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.kede.api.stand.utils.GaoDeMapUtil;
import com.kede.api.stand.utils.LogisOrderAPiUtils;
import com.kede.domain.ConfigDomain;
import com.kede.pojo.ResHttp;
import com.kede.service.ConfigService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 系统管理
 * @Author:Pr.li
 * @Date: create in 2023/6/17 17:37
 */
@RequestMapping("util")
@RestController
public class UtilController {

    @Resource
    private ConfigService configService;


    @GetMapping("getConfigByName")
    public ResHttp getConfigByName(String name){
            LambdaQueryWrapper<ConfigDomain> queryWrapper = new LambdaQueryWrapper<>();
            queryWrapper.eq(ConfigDomain::getName,name);
            ConfigDomain one = configService.getOne(queryWrapper);
        return ResHttp.okData(one);
    }

    @PostMapping("getConfigByNames")
    public ResHttp getConfigsByName(@RequestBody Map<String,String[]> map){
        List<ConfigDomain> list = new ArrayList<>();
        for (String s : map.get("names")) {
            LambdaQueryWrapper<ConfigDomain> queryWrapper = new LambdaQueryWrapper<>();
            queryWrapper.eq(ConfigDomain::getName,s);
            ConfigDomain one = configService.getOne(queryWrapper);
            list.add(one);
        }
        return ResHttp.okData(list);
    }

    /**
     * 根据经纬度 从高德获取当前位置信息
     * @param lng
     * @param lat
     * @return
     */
    @GetMapping("getAddressByLocation")
    public ResHttp getAddressByLocation(String lng,String lat){
        return ResHttp.okData(GaoDeMapUtil.getAddressComponentByLocation(lng,lat));
    }

    /**
     * 得到物流信息
     *
     * @param cpCode 快递公司编码
     * @param mailNo 快递号
     * @return {@link ResHttp}
     */
    @GetMapping("getLogisInfo")
    public ResHttp getLogisInfo(String cpCode ,String mailNo ){
        return ResHttp.okData(LogisOrderAPiUtils.getLogisInfo(cpCode,mailNo));
    }

}
